<script setup lang="ts">
import { ref, onMounted } from 'vue'
import Top from './components/top/index.vue'
import Tourist from './components/tourist/index.vue'
import Sex from './components/sex/index.vue'
import Age from './components/age/index.vue'
import Line from './components/line/index.vue'
import Map from './components/map/index.vue'
import Rank from './components/rank/index.vue'
import Couter from './components/couter/index.vue'
import Year from './components/year/index.vue'

const screen = ref()

onMounted(() => {
  screen.value.style.transform = `scalc(${getScaleFn()}) translate(-50%, -50%)`
})

// 定义大屏缩放比例
const getScaleFn = (w = 1920, h = 1080) => {
  const ww = window.innerWidth / w
  const wh = window.innerWidth / h
  return ww < wh ? ww : wh
}

// 监听视口发生变化
window.onresize = () => {
  screen.value.style.transform = `scalc(${getScaleFn()}) translate(-50%, -50%)`
}
</script>

<template>
  <div class="container">
    <div class="screen" ref="screen">
      <div class="top">
        <Top />
      </div>
      <div class="bottom">
        <div class="left">
          <Tourist />
          <Sex />
          <Age />
        </div>
        <div class="center">
          <Map/>
          <Line/>
        </div>
        <div class="right">
          <Rank class="rank" />
          <Year class="year" />
          <Couter class="couter" />
        </div>
      </div>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.container {
  width: 100vw;
  height: 100vh;
  background: url('./images/bg.png') no-repeat;
  background-size: cover;

  .screen {
    position: fixed;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    transform-origin: left top;
    width: 1920px;
    height: 1080px;

    .top {
      width: 100%;
      height: 40px;
    }

    .bottom {
      display: flex;
      width: 100%;
      
      .right {
        flex: 1;
        display: flex;
        flex-direction: column;

        .rank {
          flex: 1.5;
        }

        .year {
          flex: 1.5;
        }

        .couter {
          flex: 1.5;
        }
      }

      .left {
        flex: 1;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        height: 1040px;

        > div:first-child {
          flex: 1.2;
        }

        > div:nth-child(2) {
          flex: 1;
        }

        > div:last-child {
          flex: 1;
        }
      }

      .center { 
        flex: 2;
        display: flex;
        flex-direction: column;

        > div:first-child {
          flex: 4;
          // background-color: red;
        }
        
        > div:last-child {
          flex: 1;
          // background-color: orange;
        }
      }
    }
  }
}
</style>